/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;

import Data.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author bienphongvnn
 */
public class KhachHangModel {
     public static ArrayList<KhachHang> ListKhachHang() {	
        ArrayList<KhachHang> ds = new ArrayList<KhachHang>();	
        Connection con = ConnectionProvider.Connect();
	try {
            String sql = "SELECT * FROM khachhang";
            Statement statement	= con.createStatement();	
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){	
                KhachHang kh = new KhachHang();
                kh.TenDangNhap = rs.getString("TenDangNhap");
                kh.HoTen = rs.getString("HoTen");
                kh.CMND = rs.getString("CMND");
                kh.NgaySinh = rs.getDate("NgaySinh");
                kh.GioiTinh = rs.getInt("GioiTinh");
                kh.DiaChi = rs.getString("DiaChi");
                kh.DienThoai = rs.getString("DienThoai");
                kh.Email = rs.getString("Email");
                kh.MatKhau = rs.getString("MatKhau");
                kh.XacNhanMatKhau = rs.getString("XacNhanMatKhau");
                ds.add(kh);	
                } 
            con.close();
        }
        catch(Exception ex){
            System.out.println(ex.getMessage());	
        }
        finally
        {
           
        }
        return	ds;	
    }
     //Tim kiếm
     public static ArrayList<KhachHang> TimKiemTatCa(String keyword) {
         ArrayList<KhachHang> ds = new ArrayList<KhachHang>();
         Connection conn = ConnectionProvider.Connect();
        try {
            String sql = "Select  TenDangNhap, HoTen, CMND, NgaySinh, GioiTinh, DiaChi, DienThoai, Email, MatKhau, XacNhanMatKhau from khachhang where TenDangNhap = '" + keyword + "'";
            Statement statement	= conn.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){	
                KhachHang kh = new KhachHang();
                kh.TenDangNhap = rs.getString("TenDangNhap");
                kh.HoTen = rs.getString("HoTen");
                kh.CMND = rs.getString("CMND");
                kh.NgaySinh = rs.getDate("NgaySinh");
                kh.GioiTinh = rs.getInt("GioiTinh");
                kh.DiaChi = rs.getString("DiaChi");
                kh.DienThoai = rs.getString("DienThoai");
                kh.Email = rs.getString("Email");
                kh.MatKhau = rs.getString("MatKhau");
                kh.XacNhanMatKhau = rs.getString("XacNhanMatKhau");
                ds.add(kh);	
            }

        }catch(Exception ex){
            System.out.println(ex.getMessage());	
        }
        finally
        {
           
        }
        return	ds;	
     }
}
